#include<bits/stdc++.h>
#define  ll long long
using namespace std;

const int N = 1e5 +10;
const int M = 30;

struct nn
{
    ll d,v,a;
    double dz;
    nn(ll d1=-1,ll v1=1,ll a1=1e3+1):d(d1),v(v1),a(a1){}

}che[N];
int n,m,L,V;
int ans[M][3];
int p[N];
bool pf[N];

int ef(int w);

int main()
{
   freopen("detect.in","r",stdin);
   freopen("detect.out","w",stdout);

    int T;
    scanf("%d",&T);
    for(int ci=1;ci<=T;ci++)
    {
         memset(pf,1,sizeof(pf));

        scanf("%d%d%d%d",&n,&m,&L,&V);
        for(int i=1;i<=n;i++)
        {
            scanf("%lld%lld%lld",&che[i].d,&che[i].v,&che[i].a);

            if(che[i].a>0)
            {
                if(che[i].v<=V)
                {
                   int fu_x=1ll*(V*V-che[i].v*che[i].v)/(2*che[i].a);

                    if(fu_x+che[i].d>L)che[i].dz=-2;
                    else che[i].dz=fu_x+che[i].d;
                }
                else che[i].dz=-1;
            }
            else if(che[i].a<0)
            {
                if(che[i].v>V)
                {
                    int fu_x=1ll*(che[i].v*che[i].v-V*V)/(2*(-che[i].a));

                    che[i].dz=fu_x+che[i].d;
                }
                else che[i].dz=-2;
            }
            else
            {
                if(che[i].v>V)che[i].dz=-1;
                else che[i].dz=-2;
            }
        }

        for(int i=1;i<=m;i++)scanf("%d",&p[i]);

        for(int i=1;i<=n;i++)
        {
            if(che[i].dz==-1)
            {
                int fu=ef(che[i].d);
                if(p[fu-1]==che[i].d)fu--;
                if(fu<=m)
                {
                    ans[ci][1]++;
                    pf[fu]=false;
                }
            }
            else if(che[i].dz!=-2)
            {
                if(che[i].a>0)
                {
                    int fu=ef(che[i].dz);
                    if(fu<=m)
                    {
                        ans[ci][1]++;
                        pf[fu]=false;
                    }
                }
                else
                {
                    int fu=ef(che[i].d);
                    if(p[fu-1]==che[i].d)fu--;
                    if(p[fu]<=che[i].dz)
                    {
                        ans[ci][1]++;
                        pf[fu]=false;
                    }
                }
            }

        }
    for(int i=1;i<=m;i++)if(pf[i])ans[ci][2]++;

    }
for(int ci=1;ci<=T;ci++)printf("%d %d\n",ans[ci][1],ans[ci][2]);
return 0;
}

int ef(int w)
{
    int l=1,r=m;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(p[mid]<=w)l=mid+1;
        else r=mid-1;
    }
    return l;
}
